/*
 * @Description:
 * @Author:
 * @Date: 2024-10-05 11:58:56
 * @LastEditTime: 2024-10-06 08:56:40
 * @LastEditors: XXX
 */
console.log(123456)

class XsUser extends HTMLElement {
  constructor() {
    super()
    this.attachShadow({ mode: 'open' })
  }

  connectedCallback () {
    this.render()
  }

  render () {
    console.log('this.dataset :>> ', this.dataset);
    const dataset = this.dataset
    const userTag = document.createElement('div')
    userTag.innerHTML = `
      <div class="xs-artical__user">
        <div class="xs-artical__user-avatar">
          <img src="${dataset.avatar}" alt="">
        </div>
        <div>
          <div class="xs-artical__user-name">${dataset.name}</div>
          <div class="xs-artical__user-time">${dataset.time} ${dataset.location}</div>
        </div>
      </div>
    `

    const styles = document.createElement('style')
    styles.innerHTML = `
      .xs-artical__user {
        display: flex;
        align-items: center;
        margin-top: 15px;
      }

      .xs-artical__user-avatar {
        width: 40px;
        height: 40px;
        border-radius: 30px;
        overflow: hidden;
        margin-right: 15px;
      }

      .xs-artical__user-avatar img {
        width: 100%;
        height: 100%;
      }

      .xs-artical__user-name {
        font-size: 12px;
        color: #999;
      }

      .xs-artical__user-time {
        font-size: 12px;
        color: #999;
      }
    `

    this.shadowRoot.appendChild(userTag)
    this.shadowRoot.appendChild(styles)
  }

  addBorder () {
    const avatar = this.shadowRoot.querySelector('.xs-artical__user-avatar')
    if (avatar) {
      avatar.style.border = '3px solid red'
    }
  }
}

customElements.define('xs-user', XsUser)
export default XsUser
